package com.hyl.crmclient.controller;

import com.hyl.crmclient.common.BaseCode;
import com.hyl.crmclient.service.ChanceService;
import com.hyl.jpademo.entity.Chance;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description销售机会
 * @Author hyl
 * @Date 2022/6/6 11:30
 **/
@Controller
@RequestMapping(value = "/chance")
public class ChanceController {

	@Resource
	private ChanceService chanceService;

	@RequestMapping(value = "/list")
	public String list(@RequestParam(defaultValue = "1") Integer pageIndex,
	                   @RequestParam(required = false) String custName,
	                   @RequestParam(required = false)  String title,
	                   Model model){
		System.out.println("销售机会。。"+(pageIndex-1));

		//操作数据
		Map<String,String> param = new HashMap<String,String>();
		param.put("custName",custName);
		param.put("title",title);
		Pageable pageable = PageRequest.of(pageIndex-1, BaseCode.SHOW_SIZE);
		Page<Chance> page =  chanceService.findPageByParam(param,pageable);

		//传递数据
		model.addAttribute("chancePage",page);
		model.addAttribute("param",param);
		return "chance/list";
	}

	@RequestMapping(value = "/add")
	@RequiresPermissions(value = "销售机会新增")
	public String add(){
		System.out.println("添加 销售机会。。");
		return "chance/add";
	}

	@RequestMapping(value = "/edit/{chcId}")
	public String edit(@PathVariable Integer chcId){
		System.out.println("编辑销售机会。。");
		return "chance/edit";
	}
}
